﻿//========================================================= 
/**@file ICCardLeAdapter.h
 * @brief 在APDU后面补足LE的适配器
 * 
 * @date 2017-08-20   09:03:55
 * @author Zhyioo 
 * @version 1.0
 */ 
//--------------------------------------------------------- 
#ifndef _LIBZHOUYB_ICCARDLEADAPTER_H_
#define _LIBZHOUYB_ICCARDLEADAPTER_H_
//--------------------------------------------------------- 
#include "../../include/Base.h"
//--------------------------------------------------------- 
namespace zhou_yb {
namespace application {
namespace iccard {
//--------------------------------------------------------- 
/// 带LE参数的指令适配器(用于处理VISA,MASTE卡)
class ICCardLeAdapter : 
    public ITransceiveTrans,
    public BaseDevAdapterBehavior<ITransceiveTrans>,
    public RefObject
{
protected:
    ByteBuilder _apduBuff;
public:
    ICCardLeAdapter(bool isLE = false) : IsFixedLE(isLE) {}
    virtual bool TransCommand(const ByteArray& send, ByteBuilder& recv)
    {
        if(_pDev.IsNull())
            return false;
        ByteArray sApdu(send);
        // 检查是否需要补LE
        if(IsFixedLE)
        {
            size_t lc = send[ICCardLibrary::LC_INDEX];
            if(lc > 0)
            {
                _apduBuff.Clear();
                _apduBuff.Append(send);
                _apduBuff += static_cast<byte>(0x00);
                sApdu = _apduBuff;
            }
        }
        return _pDev->TransCommand(sApdu, recv);
    }
    bool IsFixedLE;
};
//--------------------------------------------------------- 
} // namespace iccard
} // namespace application
} // namespace zhou_yb
//--------------------------------------------------------- 
#endif // _LIBZHOUYB_ICCARDLEADAPTER_H_
//========================================================= 